home *** CD-ROM | disk | FTP | other *** search
- From: John Vilburn <JVilburn@novell.com>
- Organization: Novell, Inc.
- X-Mailer: Mozilla 1.2N (Windows; I; 32bit)
- MIME-Version: 1.0
- Newsgroups: comp.lang.c
- Subject: Re: sscanf problems
- References: <4e4c2v$j2g@mathserv.mps.ohio-state.edu>
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- NNTP-Posting-Host: jvilburn.npd.provo.novell.com
- Message-ID: <3106fabd.0@news.provo.novell.com>
- Date: 25 Jan 96 03:36:29 GMT
- Path: news.provo.novell.com!
-
- Chris Mongold <cmongold@magnus.acs.ohio-state.edu> wrote:
- >Hello,
- > I'm sorry if this is an inappropriate topic, but I've tried
- >everything else. I can't seem to get sscanf to to separate a string
- >into various variable types. Here is an example:
- >
- >#include <stdio.h>
- >
- >void main()
- >{
- >char input[20], crap[17], segment[6], seg_len[3], begin[3], load[3];
- >int type;
- >FILE *fp;
- >
- >printf("File: ");
- >gets(input);
- >
- >fp = fopen(input, "r");
- >
- >while(!feof(fp))
- >{
- >fgets(crap, 17, fp);
- >sscanf(crap, "%d%3s%6s%3s%3s", type, begin, segment, seg_len, load);
- >printf("%d %3s %6s %3s %3s", type, begin, segment, seg_len, load);
- >
- >}
- >}
- >No matter what I do, it always 'bus errors' when I sscanf. I've tried
- >it several different ways, including making crap larger, but to
- >no avail. If anyone can help me, I would greatly appreciate it.
- >Please respond to cmongold@magnus.acs.ohio-state.edu
- >
- >Thanks,
- >
- >Chris
-
- I think you may be telling sscanf that "type" can hold 3
- characters. It can actually hold only 2 because the string
- needs to be null terminated. The same is true for the other
- destination strings. Try declaring each of them to be one byte
- longer.
-
-